package com.example.administrator.swredeem.activity;

import android.arch.lifecycle.Observer;
import android.content.Intent;
import android.device.IccManager;
import android.device.PrinterManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.example.administrator.swredeem.R;
import com.example.administrator.swredeem.utils.LiveDataBus;
import com.example.administrator.swredeem.utils.ReadCard;
import com.google.gson.Gson;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    Intent intent = null;
    Gson gson = new Gson();
    @BindView(R.id.titleBar)
    TitleBar titleBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        init();
    }


    private void init() {
        titleBar.setTitle("首页");
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {
            }
            @Override
            public void onRightClick(View v) {

            }
        });
        LiveDataBus.get().with("key_hxg").setValue("测试使用LiveDataBus");

    }

    //抄表
    public void goCB(View view) {
        startActivity(new Intent(MainActivity.this, GongdanListActivity.class));

    }

    //建档
    public void goService(View view) {
        startActivity(new Intent(MainActivity.this, SelectServiceActivity.class));
    }

    //查询
    public void goQuery(View view) {
        startActivity(new Intent(MainActivity.this, SelectServiceActivity.class));
    }

    public void goCircle(View view) {
        startActivity(new Intent(MainActivity.this, CircleOfDepositICActivity.class));
    }

    //充值
    public void goRecharge(View view) {
        startActivity(new Intent(MainActivity.this, RechargeICActivity.class));
    }

    //开户申请
    public void goOpencard(View view) {
        intent = new Intent(MainActivity.this, KaihuSqActivity.class);
        intent.putExtra("title", "开卡");
        startActivity(intent);
    }

    //补卡
    public void goReissuecard(View view) {
        intent = new Intent(MainActivity.this, OpenCardICActivity.class);
        intent.putExtra("title", "补卡");
        startActivity(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        LiveDataBus.get()
                .with("key_hxg", String.class)
                .observe(this, new Observer<String>() {
                    @Override
                    public void onChanged(@Nullable String s) {
                        Log.e("huangxiaoguo", s);
                    }
                });
    }

    //弹出选项框






    public void dayin(View view) {
        //初始化实例
        PrinterManager printer = new PrinterManager();
        //设置页面大小 参数从查看实例
        printer.setupPage(384, -1);
        printer.drawLine(264, 50, 48, 50, 4);
        printer.drawLine(156, 0, 156, 120, 2);
        printer.drawLine(16, 0, 300, 100, 2);
        printer.drawLine(16, 100, 300, 0, 2);
        //添加附加文本 参数从查看实例
        int ret = printer.drawTextEx("汪佳豪\n汪佳豪\n汪佳豪\n", 5, 0, 384, -1, "simsun", 24, 0, 0, 0);
        //开始打印
        printer.printPage(0);
    }


    //读卡
    public void readCard(View v) {
        ReadCard readCard = new ReadCard();
        readCard.readIC(MainActivity.this);
        IccManager iccManager = new IccManager();
    }


}
